<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>

    <meta charset="UTF-8">
    <title>Basic CRUD Application - jQuery EasyUI CRUD Demo</title>
<link rel="stylesheet" type="text/css" href="../js/util/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../js/util/easyui/themes/icon.css">
 <link rel="stylesheet" type="text/css" href="../js/util/easyui/themes/color.css">
 <link rel="stylesheet" type="text/css" href="../js/util/easyui/demo/demo.css"> 
<script type="text/javascript" src="../js/util/jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../js/util/easyui/jquery.easyui.min.js"></script>



   

</head>
<body>
    <h2>用户管理界面</h2>
    
    
    <table id="dg" title="我的订单信息" class="easyui-datagrid" style="width:700px;height:250px"
            url="../myOrderServlet/queryOrder"
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true">
        <thead>
            <tr>
              
                <th field="orderid" width="35">订单编号</th>
                <th field="userid" width="35">用户编号</th>
                <th field="username" width="50">用户名</th>
                <th field="ticketid" width="50">车票编号</th>
                <th field="orderstate" width="50">订单状态</th>
                <th field="price" width="50">票价</th>
                <th field="ordertime" width="80" formatter="formattime">出票日期</th>
                
            </tr>
        </thead>
    </table>
    <div id="toolbar">

         <a href="#" class="easyui-linkbutton c1" style="width:120px" onClick="takeOrder()">取票</a>
        <a href="#" class="easyui-linkbutton c6" style="width:120px" onClick="editOrder()" >改签</a>
        <a href="#" class="easyui-linkbutton c5" style="width:120px" onClick="cancelTicket()">退票</a>
      
    </div>
     <!-- -取票-->
    <div id="dlg" class="easyui-dialog" style="width:400px"
            closed="true" buttons="#dlg-buttons">
        <form id="fm" action="../myOrderServlet/takeOrder" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">请输入您的身份证号</div>
         
            <div style="margin-bottom:10px">
                <input id="cardid" name="cardid" class="easyui-textbox"  label="身份证号:" style="width:100%">
                <input type="text" style="display:none;">
            </div>    
    </form>
    
      </div>
       <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveOrder()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
    </div>
     <!-- -退票 -->
      <div id="adlg" class="easyui-dialog" style="width:400px"
            closed="true" buttons="#dlg-buttons">
     <form id="afm" action="../myOrderServlet/cancelTicket"  method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">请输入您的身份证号</div>
            <div style="margin-bottom:10px">
                <input  id="cardid1" name="cardid" class="easyui-textbox" label="身份证号:" style="width:100%">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#adlg').dialog('close')" style="width:90px">Cancel</a>
    </div>
    
    <!-- -改签 -->
    <div id="bdlg" class="easyui-dialog" style="width:400px"
            closed="true" buttons="#dlg-buttons">
     <form id="bfm" action="../myOrderServlet/takeOrder" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:2px #ccc">您确认要改签吗？</div>
    
     </form>
     </div>
       <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="confirm()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#bdlg').dialog('close')" style="width:90px">Cancel</a>
    </div>     
  
    <script type="text/javascript">
        var url;
        function takeOrder(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','取票');
                $('#fm').form('load',row);
                url = '../myOrderServlet/takeOrder?id='+row.id;
             /*    alert(row.orderid);    */
        
            }else {
                $.messager.alert({
                    title: '系统提示',
                    msg: '请选择需要修改的行'
                });
            }
        }
        
        
        function saveOrder(){
        	
            var row = $('#dg').datagrid('getSelected');
            var cardid=document.getElementById("cardid").value;
            var express=/^(^\d{18}$)|(^\d{17}[Xx]$)$/;
            if(!express.test(cardid)){
          	alert("输入的身份证号有误");
            }

            
          	 $.ajax({
              	 url:'../myOrderServlet/takeOrder',
              	 cache:false,
              	 dataType:"JSON",
              	 type:"POST",
              	 data:{
              		 "orderid":row.orderid,     
              		 "cardid":cardid,
              		  
              	 },
              	success:function(result){
              		 if (result == "1") {
                         $.messager.alert("提示信息", "取票成功");
           		 /* Dialog.alert("提示：你点击了一个按钮");*/
           		 /*  alert("取票成功");*/
           		 $('#dlg').dialog('close');   
           		 $('#dg').datagrid("reload",{});
           	 } else {
                 $.messager.alert("提示信息", "取票失败");
             }
              	}
            });
       }
        
        
        function cancelTicket(){
       	 var row = $('#dg').datagrid('getSelected');
       	
            if (row){
                $('#adlg').dialog('open').dialog('center').dialog('setTitle','退票');
                $('#afm').form('load',row);
              /*url = '../myOrderServlet/cancelTicket?id='+row.id;*/
                
            }else {
                $.messager.alert({
                    title: '系统提示',
                    msg: '请选择需要修改的行'
                });
            }
                
       }
        
        function saveUser(){
        	
         var row = $('#dg').datagrid('getSelected');
       	 var cardid1=document.getElementById("cardid1").value;
         var express=/^(^\d{18}$)|(^\d{17}[Xx]$)$/;
         if(!express.test(cardid)){
       	 alert("输入的身份证号有误");
         }
       	 $.ajax({
           	 url:'../myOrderServlet/cancelTicket',
           	 cache:false,
           	 dataType:"JSON",
           	 type:"POST",
           	 data:{
           		 "orderid":row.orderid,     
           		 "cardid":cardid1,
           		  
           	 },
           	 success:function(result){
           		if (result == "1") {
                    $.messager.alert("提示信息", "退票成功");
      		 /* Dialog.alert("提示：你点击了一个按钮");*/
      		 /*  alert("取票成功");*/
      		 $('#adlg').dialog('close');   
      		 $('#dg').datagrid("reload",{});
      	 } else {
            $.messager.alert("提示信息", "退票失败");
        }
         	}
            });
       }
        	
        function editOrder(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
            	 $('#bdlg').dialog('open').dialog('center').dialog('setTitle','提示');
            	 $('#bfm').form('load',row);
            }
        }
            
            function confirm(){
            	var row = $('#dg').datagrid('getSelected');
            	
            	$.ajax({
                  	 url:'../myOrderServlet/editOrder',
                  	 cache:false,
                  	 dataType:"JSON",
                  	 type:"POST",
                  	 data:{
                  		 "orderid":row.orderid,     
                  		  
                  	 },
                  	 success:function(result){
                  		if (result == "1") {
                            $.messager.alert("提示信息", "改签成功");
              		 /* Dialog.alert("提示：你点击了一个按钮");*/
              		 /*  alert("取票成功");*/
              		 $('#bdlg').dialog('close');   
              		 $('#dg').datagrid("reload",{});
              	 } else {
                    $.messager.alert("提示信息", "改签失败");
                }
                 	}
                   });
              }	
        
            
            function formattime(val) {  
            	 var date = new Date(val);
                 var year = date.getFullYear().toString();
                 var month = (date.getMonth() + 1);
                 var day = date.getDate().toString();
                 var hour = date.getHours().toString();
                 var minutes = date.getMinutes().toString();
                 var seconds = date.getSeconds().toString();
                 if (month < 10) {
                     month = "0" + month;
                 }
                 if (day < 10) {
                     day = "0" + day;
                 }
                 if (hour < 10) {
                     hour = "0" + hour;
                 }
                 if (minutes < 10) {
                     minutes = "0" + minutes;
                 }
                 if (seconds < 10) {
                     seconds = "0" + seconds;
                 }
     
                 return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
            } 

       
       
       
    </script>
</body>
</html>